package com.ruoyi.user.service.impl;

import com.ruoyi.user.domain.MerchantProduct;
import com.ruoyi.user.domain.vo.ProductBriefVO;
import com.ruoyi.user.domain.vo.ProductDetails;
import com.ruoyi.user.domain.vo.ProductSpecDetailVO;
import com.ruoyi.user.domain.vo.ProductSpecGroupVO;
import com.ruoyi.user.mapper.UserProductMapper;
import com.ruoyi.user.service.IUserProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import java.util.List;

@Service
public class UserProductServiceImpl implements IUserProductService {
    @Resource
    private UserProductMapper userProductMapper;

    @Override
    public java.util.List<String> listCategoryNamesByMerchant(Long merchantId) {
        return userProductMapper.selectProductsCategoryNameByMerchantId(merchantId);
    }

    @Override
    public java.util.List<MerchantProduct> listProductsByMerchant(Long merchantId) {
        return userProductMapper.selectProductsByMerchantId(merchantId);
    }

    @Override
    public ProductDetails getProductSpecs(Long productId) {
        ProductBriefVO brief = userProductMapper.selectProductBriefById(productId);
        java.util.List<ProductSpecGroupVO> groups = userProductMapper.selectSpecGroupsByProductId(productId);
        java.util.List<ProductSpecDetailVO> details = userProductMapper.selectSpecDetailsByProductId(productId);
        com.ruoyi.user.domain.vo.ProductDetails vo = new com.ruoyi.user.domain.vo.ProductDetails();
        if (brief != null) {
            try { vo.setProductId(Long.valueOf(brief.getProductId())); } catch (Exception ignored) {}
            vo.setName(brief.getName());
            vo.setImageUrl(brief.getImageUrl());
            vo.setRegionPrice(brief.getRegionPrice());
            vo.setMarketPrice(brief.getMarketPrice());
        }
        vo.setSpecGroups(groups);
        vo.setSpecDetails(details);
        return vo;
    }
}
